YUI.add('javascript-article', function (Y) {
    /* Any frequently used shortcuts, strings and constants */
    var Lang = Y.Lang;

    /* JavascriptArticle class constructor */
    function JavascriptArticle(config) {
        JavascriptArticle.superclass.constructor.apply(this, arguments);
    }

    /* 
     * Required NAME static field, to identify the class and 
     * used as an event prefix, to generate class names etc. (set to the 
     * class name in camel case). 
     */
    JavascriptArticle.NAME = "JavascriptArticle";
    
    JavascriptArticle.JSONP_URL = "http://www.m3958.com";
    
    if(window.location.href.indexOf('8888') != -1){
    	JavascriptArticle.JSONP_URL = "http://127.0.0.1:8888";
    }

    /*
     * The attribute configuration for the component. This defines the core user facing state of the component
     */
    JavascriptArticle.ATTRS = {
    	article : {
    		value : null
    	},
        attrA : {
            value: "A"                     // The default value for attrA, used if the user does not set a value during construction.

            /*
            , valueFn: "_defAttrAVal"      // Can be used as a substitute for "value", when you need access to "this" to set the default value.
             
            , setter: "_setAttrA"          // Used to normalize attrA's value while during set. Refers to a prototype method, to make customization easier
            , getter: "_getAttrA"          // Used to normalize attrA's value while during get. Refers to a prototype method, to make customization easier
            , validator: "_validateAttrA"  // Used to validate attrA's value before updating it. Refers to a prototype method, to make customization easier

            , readOnly: true               // Cannot be set by the end user. Can be set by the component developer at any time, using _set
            , writeOnce: true              // Can only be set once by the end user (usually during construction). Can be set by the component developer at any time, using _set
            
            , lazyAdd: false               // Add (configure) the attribute during initialization. 
            
                                           // You only need to set lazyAdd to false if your attribute is
                                           // setting some other state in your setter which needs to be set during initialization 
                                           // (not generally recommended - the setter should be used for normalization. 
                                           // You should use listeners to update alternate state). 

            , broadcast: 1                 // Whether the attribute change event should be broadcast or not.
            */
        }

        // ... attrB, attrC, attrD ... attribute configurations. 

        // Can also include attributes for the super class if you want to override or add configuration parameters
    };

    /* JavascriptArticle extends the Base class */
    Y.extend(JavascriptArticle, Y.Base, {
        initializer: function() {
            /*
             * initializer is part of the lifecycle introduced by 
             * the Base class. It is invoked during construction,
             * and can be used to setup instance specific state or publish events which
             * require special configuration (if they don't need custom configuration, 
             * events are published lazily only if there are subscribers).
             *
             * It does not need to invoke the superclass initializer. 
             * init() will call initializer() for all classes in the hierarchy.
             */
//        	this.cached = null;
//             this.publish("sectionReady", {
//                defaultFn: this._onSectionReady,
//                bubbles:false
//             });
        },

        destructor : function() {
            /*
             * destructor is part of the lifecycle introduced by 
             * the Base class. It is invoked when destroy() is called,
             * and can be used to cleanup instance specific state.
             *
             * It does not need to invoke the superclass destructor. 
             * destroy() will call initializer() for all classes in the hierarchy.
             */
//        	this.sectionHash = null;
        },
        
        gett : function(fieldName){
        	return this.get('article')[fieldName];
        },
        //2011-10-29T00:55:53
        getPublishedAt : function(ftm){
        	var dtStr = this.gett('publishedAt');
        	if(!ftm)return dtStr;
        	var	dateTime = dtStr.split('T'),
        		dates = dateTime[0].split('-'),
        		times = dateTime[1].split(':');
        	var rs = ftm.replace('yyyy',dates[0]).replace('yy',dates[0].substring(2)).replace('mm',dates[1]).replace('dd',dates[2]);
        	return rs;
        },
        getTitle : function(len,postfix){
        	var t = this.gett('title');
        	var al = arguments.length;
        	if(al == 1){
        		return t.substring(0,len);
        	}else if(al == 2){
        		if(t.length > len){
        			return t.substring(0,len) + postfix;
        		}else{
        			return t;
        		}
        	}else{
        		return t;
        	}
        },
        
        getKv : function(k){
        	var kv = this.gett('keyvalues');
        	var kvs = kv.split(',');
        	return Y.Array.find(kvs,function(item){
        		var a = item.split('=');
        		if(a.length == 2){
        			if(Y.Lang.trim(a[0]) == k){
        				return Y.Lang.trim(a[1]);
        			}
        		}
        	});
        },
        doSomethingPublic : function() {
            // Public method
        },

        _doSomethingPrivate : function() {
            // Private/Protected method
        },

        _onSectionReady : function(e) {
            // The default behavior for the "siteReady" event.
        }
    });
  
/*		
_endRow=50&_isMaster=false&_modelName=com.m3958.firstgwt.server.model.Article&_operationType=fetch&_relationModelId=18245&_relationModelName=com.m3958.firstgwt.server.model.Section&_relationPropertyName=articles&_sortBy=-createdAt&	_startRow=0&_subOperationType=MANY_TO_MANY&_textMatchStyle=substring
*/		
    Y.namespace("M3958").JavascriptArticle = JavascriptArticle;

},'0.0.1',{requires:['base','jsonp', 'jsonp-url','dump','node','array-extras']});